//
//  UIViewController+hud.swift
//  clreader
//
//  Created by colin on 2019/2/26.
//  Copyright © 2019 colin. All rights reserved.
//

import UIKit
import MBProgressHUD

extension UIViewController {
    
    public var hud:Hud {
        return Hud(view: self.view)
    }
    
    public struct Hud {
        private var view:UIView
        
        init(view:UIView) {
            self.view = view
        }
        
        public func showProgress(_ info:String? = nil) {
            let hud = MBProgressHUD.showAdded(to: self.view, animated: true)
            hud.animationType = .fade
            hud.mode = .indeterminate
            hud.label.text = info
        }
        
        public func showText(_ info:String?) {
            let hud = MBProgressHUD.showAdded(to: self.view, animated: true)
            hud.animationType = .fade
            hud.mode = .text
            hud.label.text = info
            hud.hide(animated: true, afterDelay: 1.5)
        }
        
        public func hide() {
            MBProgressHUD.hide(for: self.view, animated: true)
        }
        
    }
}
